package com.orange.score.utils;

import android.content.Context;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class FileService
{
  public static String DATE_FORMAT = "yyMMddHH";
  public static final String TAG = "FileService";
  private Context context;

  public FileService(Context paramContext)
  {
    this.context = paramContext;
  }

  public static String currentDate()
  {
    return dateToStringByFormat(new Date(), DATE_FORMAT);
  }

  public static String dateToStringByFormat(Date paramDate, String paramString)
  {
    String str;
    if ((paramDate == null) || (paramString == null))
      str = null;
    while (true)
    {
      return str;
      SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString);
      localSimpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
      str = localSimpleDateFormat.format(paramDate);
    }
  }

  public String read(String paramString)
    throws Exception
  {
    FileInputStream localFileInputStream = this.context.openFileInput(paramString);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    byte[] arrayOfByte = new byte[1024];
    while (true)
    {
      int i = localFileInputStream.read(arrayOfByte);
      if (i == -1)
      {
        localFileInputStream.close();
        localByteArrayOutputStream.close();
        return localByteArrayOutputStream.toString();
      }
      localByteArrayOutputStream.write(arrayOfByte, 0, i);
    }
  }

  public void save(String paramString1, String paramString2)
  {
    Log.d("FileService", "save repository info to " + paramString1);
    try
    {
      FileOutputStream localFileOutputStream = this.context.openFileOutput(paramString1, 0);
      localFileOutputStream.write(paramString2.getBytes());
      localFileOutputStream.close();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
}